﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ToExternalServer.aspx.cs" Inherits="SignalR_Persistent.ToExternalServer" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
                <asp:TextBox ClientIDMode="Static" ID="msg" runat="server" />
        <asp:Button ClientIDMode="Static" ID="broadcast" runat="server" OnClientClick="startConnection()" />

    </div>
    </form>

    <script src="http://code.jquery.com/jquery-1.7.min.js" type="text/javascript" ></script>
    <script src="Scripts/jquery.signalR-1.0.0-rc2.min.js" type="text/javascript" ></script>
    <script type="text/javascript" >

        var connection = null;
        var messageHub = null;

        $(function () {
            connection = $.hubConnection('http://localhost:1802');
            messageHub = connection.createHubProxy('MessageHub');

            connection.start().done(function () {
                $("#broadcast").click(function () {
                    alert('Starting connection...');
                    connection.send($('#msg').val());
                });
            });


        });

        function startConnection() {
            alert('Called startConnection()...');
            //connection.start().done(function () {
            //    $("#broadcast").click(function () {
            //        alert('Starting connection...');
            //        connection.send($('#msg').val());
            //    });
            //});

            messageHub.on('Send', function (message) {
                SuccessHandler(message);
                // Turn logging on so we can see the calls in the browser console 
                connection.logging = true;
                // Start the connection 
                connection.start().done(function () {
                    alert("Now connected!");
                }).fail(function () {
                    alert("Could not Connect!");
                });

            });

            function SuccessHandler(jObject) {
                // Do Work with the object 

            }


        }

    </script>

</body>
</html>
